package ahpu.piconet.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ahpu.piconet.dao.UserDao;
import ahpu.piconet.domin.User;

@Repository
public class UserDaoImpl implements UserDao{

	@Autowired
	private SessionFactory factory; 
	
	public  Session getSession(){
		return factory.openSession();
	}
	
	
	@Override
	public User login(String username) throws Exception {
		String hql="from User u where u.username = ?";
		Query query=getSession().createQuery(hql).setString(0, username);
		return (User) query.uniqueResult();
	}

}
